if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.user.AddSuperUsers")) {
	jsx3.require("jsx3.gui.Dialog")
/**
*
*/
jsx3.lang.Package.definePackage("tibco.admin.enterpriseAssets.userMgt.user", function (addSuperUsers) {
});

/**
 * Extension of the <code>jsx3.gui.Dialog</code> class, for use in User Management, to add super user.
 */
jsx3.lang.Class.defineClass("tibco.admin.enterpriseAssets.userMgt.user.AddSuperUsers",
        jsx3.gui.Dialog,
        null,
        function (addSuperUsers) {

			/**
			 * instance initializer
			 */
			addSuperUsers.prototype.initialize = function() {
				// set the window instance id
                    if (jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.window.Window")) {
                        this.window = this.getAncestorOfType(tibco.admin.enterpriseAssets.userMgt.window.Window)
                        if (this.window) {
                            this.setWindowId(this.window.getId());
                        }
                    }
				// set the matrix
				this.userRsList = this.getDescendantOfName("mtxSearchRs_24_N_2");
				this.mtxUsersAdd = this.getDescendantOfName("mtxAddUsers_24_N_2");
				this.searchBtn = this.getDescendantOfName("btnSearch_24_N_2");
				this.saveBtn = this.getDescendantOfName("btnSaveUser_24_N_2");
				var curMe = this;
				this.searchBtn.callsearchUsers = function(){
					curMe.callsearchUsers();
				}
				this.mtxUsersAdd.onDelete = function(recordId){
					curMe.onDelete(recordId);
				}
				this.saveBtn.calladdSuperUsers = function(){
					curMe.calladdSuperUsers();
				}
			}

			 /**
			  *   set the current window ID
			  *   @para strId {string} The window id
			  */
			 addSuperUsers.prototype.setWindowId = function(strId) {
                    this.windowId = strId
                }

			/**
			 *@param strName {String} ?the unique name of the window to create
			 **/
			addSuperUsers.prototype.getWindowId = function() {
				return this.windowId
			}


			/**
			 *   get the current window ID
			 *   @return {string} The window id
			 */
			addSuperUsers.prototype.onDelete = function(recordId){
				var transRecord = this.mtxUsersAdd.getRecordNode(recordId);
				this.mtxUsersAdd.deleteRecord(recordId,true);
				try
				{
					this.userRsList.insertRecordNode(transRecord,"jsxroot",true);
					this.mtxUsersAdd.repaint();
				}
				catch (ex)
				{
					 tibco.admin.Main.logException(ex, "Error in tibco.admin.enterpriseAssets.userMgt.user.AddGroups.onDelete");
				}
			}





			//==================== do search users ============================
				/**
				 *	Search Users to add super users - webservice call
				 */
				addSuperUsers.prototype.callsearchUsers = function() {
				  var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/user/rules/searchUsers4Superuser.xml", "searchUsers", "Search Users");
				  objService.subscribe(jsx3.net.Service.ON_SUCCESS, this,this.onsearchUsersSuccess);
				  //objService.subscribe(jsx3.net.Service.ON_ERROR, this,this.onsearchUsersError);
				  //objService.subscribe(jsx3.net.Service.ON_INVALID, this,this.onsearchUsersInvalid);
				  objService.searchLimit = 500;
				  objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
				  objService.doCall();
				};

				addSuperUsers.prototype.onsearchUsersSuccess = function(objEvent) {
				  var sourceXML = objEvent.target.getInboundDocument();
				  this.userRsList.setSourceXML(sourceXML);
				  this.userRsList.repaint();
				};

				addSuperUsers.prototype.onsearchUsersError = function(objEvent) {
				};

				addSuperUsers.prototype.onsearchUsersInvalid = function(objEvent) {
				  tibco.admin.util.Log.USERMGT.error("Invalid","The following message node just failed validation:\n\n" + objEvent.message);
				};



				//================== do Save ====================
				/**
				 *	   Add super user - webservice call
				 */
				addSuperUsers.prototype.calladdSuperUsers = function() {
				  var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/user/rules/addSuperUsers.xml", "addSuperUsers", "Add Super Users");
				  //subscribe and call
				  objService.subscribe(jsx3.net.Service.ON_SUCCESS, this,this.onaddSuperUsersSuccess);
				  //objService.subscribe(jsx3.net.Service.ON_ERROR, this,this.onaddSuperUsersError);
				  //objService.subscribe(jsx3.net.Service.ON_INVALID, this,this.onaddSuperUsersInvalid);
				  objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
				  objService.doCall();
				};

				addSuperUsers.prototype.onaddSuperUsersSuccess = function(objEvent) {
				   this.doClose();
				   var msg = new Object();
					msg.subject = tibco.admin.enterpriseAssets.userMgt.EventID.ADD_ITEM_SUCCESS
					msg.windowId = this.getWindowId();
					tibco.admin.PubSub.publish(msg);
				  //var responseXML = objEvent.target.getInboundDocument();
				  //objEvent.target.getServer().alert("Success","The service call was successful.");
				};

				addSuperUsers.prototype.onaddSuperUsersError = function(objEvent) {
				  var myStatus = objEvent.target.getRequest().getStatus();
				  tibco.admin.util.Log.USERMGT.error("Error","The service call failed. The HTTP Status code is: " + myStatus);
				};

				addSuperUsers.prototype.onaddSuperUsersInvalid = function(objEvent) {
				  tibco.admin.util.Log.USERMGT.error("Invalid","The following message node just failed validation:\n\n" + objEvent.message);
				};

        });
    }